﻿using System;
using System.Collections.Generic;
using System.IO;
using System.ServiceModel.Activation;
using Backup.Services.Entities;
using Backup.Services.Logic;
using Backup.Services.Logic.Authentification;
using BackupObjects;
using BackupWebRole.Models;

namespace BackupWebRole.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class BackupWebService : IBackupWebService
    {
        private readonly IBackupServiceLogic _backupServiceLogic;

        public BackupWebService()
        {
            _backupServiceLogic = new BackupServiceLogic();
        }

        public BackupEntity LoadById(Guid id, string userName, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.LoadById(id, userName);
        }

        public BackupEntity LoadByName(string name, string userName, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.LoadByName(name, userName);
        }

        public List<BackupEntity> LoadAll(string userName, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.LoadAll(userName);
        }

        public void Save(BackupEntity backupEntity, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            _backupServiceLogic.Save(backupEntity);
        }

        public void Delete(Guid id, string userName, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            _backupServiceLogic.Delete(id, userName);
        }

        public Stream GetBackupStream(Guid id, string userName, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.GetBackupStream(id, userName);
        }

        public List<BackupEntity> GetBackupEntitiesByTags(List<Guid> tagids, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.GetBackupEntitiesByTags(tagids);
        }

        public List<BackupEntity> GetBackupEntitiesByTag(Guid tagid, Credentials credentials)
        {
            AuthentificationHelper.AuthentificateUser(credentials);
            return _backupServiceLogic.GetBackupEntitiesByTag(tagid);
        }
    }
}
